package com.qihetimes.earthangel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qihetimes.earthangel.common.ResponseResult;
import com.qihetimes.earthangel.model.Conversation;
import com.qihetimes.earthangel.model.ConversationMessage;
import com.qihetimes.earthangel.model.bo.ConversationBO;
import com.qihetimes.earthangel.model.bo.ConversationShowBO;
import com.qihetimes.earthangel.model.bo.MessageSendBO;
import com.qihetimes.earthangel.service.IConversationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 会话控制器
 *
 * @author ：f4cklangzi@gmail.com
 * @date ：Created At 2021/12/18
 */
@Slf4j
@Api(tags = "会话模块")
@RestController
@RequestMapping("/api/conversation")
public class ConversationController {
    
    @Resource
    private IConversationService conversationService;
    
    @ApiOperation(value = "会话列表")
    @PostMapping("/list")
    public ResponseResult<Page<Conversation>> list(@RequestBody ConversationBO param) {
        Page<Conversation> res = conversationService.list(param);
        return ResponseResult.success(res);
    }
    
    @ApiOperation(value = "发起会话")
    @PostMapping("/create")
    public ResponseResult<Conversation> create(@RequestParam String userId, String goodsId) {
        Conversation conversation = conversationService.create(userId,goodsId);
        return ResponseResult.success(conversation);
    }
    
    @ApiOperation(value = "进入会话")
    @PostMapping("/show")
    public ResponseResult<Page<ConversationMessage>> show(@RequestBody ConversationShowBO param) {
        Page<ConversationMessage> res = conversationService.show(param);
        return ResponseResult.success(res);
    }
    
    @ApiOperation(value = "发送消息")
    @PostMapping("/send")
    public ResponseResult<String> send(@RequestBody MessageSendBO param) {
        conversationService.send(param);
        return ResponseResult.success();
    }
}
